package com.kronos.managers;

import com.kronos.game.KronosGame;
import com.kronos.gamestates.GameState;
import com.kronos.gamestates.IntroState;
import com.kronos.gamestates.LoginState; 
import com.kronos.gamestates.MenuState;

public class GameStateManager {

	private KronosGame game;
	private GameState gameState;
	private int currentState;
	
	public static final int INTRO_STATE = 0;
	public static final int LOGIN_STATE = 1;
	public static final int MENU_STATE = 2; 
	
	public GameStateManager(KronosGame game) {
		this.game = game;
		this.currentState = INTRO_STATE;
		
		loadState(currentState);
	}
	
	private void loadState(int state) {
		if (state == INTRO_STATE) {
			gameState = new IntroState(this);
		} else if (state == LOGIN_STATE) {
			gameState = new LoginState(this);
		} else if (state == MENU_STATE) {
			gameState = new MenuState(this);
		}  
	}
	
	public int getState () {
		return currentState;
	}

	public void setState (int state) {
		currentState = state; 
		loadState(this.currentState);
	}
	
	public void update() {
		if(gameState != null) {
			gameState.update();
		}
	}
	
	public void render() {
		if(gameState != null) { 
			gameState.render();
		}
	}
	
	public void dispose() {
		if(gameState != null) { 
			gameState.dispose();
		}
	}
	
	public KronosGame game() {
		return game;
	}
}
